package com.marketingManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.pojo.SmsAdvertisePosition;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.marketingManagement.dao.advertisePositionMapper;
import com.marketingManagement.service.advertisePositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author caoch
 * @since 2023/3/1 9:44
 **/
@Service
public class advertisePositionServiceImpl extends ServiceImpl<advertisePositionMapper, SmsAdvertisePosition> implements advertisePositionService {
	@Autowired
	private advertisePositionMapper advertisePositionMapper;

	/**
	 * 添加广告位置
	 * @param position
	 * @return int
	 */
	public int addAdvertisePosition(SmsAdvertisePosition position) {
		return advertisePositionMapper.insert(position);
	}

	/**
	 * 修改广告位置
	 * @param position
	 * @return int
	 */
	public int updateAdvertisePosition(SmsAdvertisePosition position){
		QueryWrapper<SmsAdvertisePosition> wrapper = new QueryWrapper<>();
		wrapper.eq("id",position.getId());
		return advertisePositionMapper.update(position,wrapper);
	}

	/**
	 * 删除广告位置
	 * @param id
	 * @return int
	 */
	public int removeAdvertisePosition(int id){
		return advertisePositionMapper.deleteById(id);
	}

	/**
	 * 查询广告位置
	 * @param currentPage
	 * @param pageSize
	 * @param position
	 * @return list
	 */
	public PageInfo<SmsAdvertisePosition> selectAdvertisePosition(Integer currentPage, Integer pageSize, SmsAdvertisePosition position){
		PageHelper.startPage(currentPage,pageSize);
		QueryWrapper<SmsAdvertisePosition> wrapper = new QueryWrapper<>();
		wrapper.like(position.getName()!=null,"name",position.getName());
		List<SmsAdvertisePosition> smsAdvertisePositions = advertisePositionMapper.selectList(wrapper);
		PageInfo<SmsAdvertisePosition> smsAdvertisePositionPageInfo = new PageInfo<>(smsAdvertisePositions);
		return smsAdvertisePositionPageInfo;
	}
}
